package com.leon.rose.common.utils;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

public class CodeGenerator {

  public static void main(String[] args) {

    AutoGenerator mpg = new AutoGenerator();

    // 全局配置
    String outputDir = "D:/workspace/temp";
    GlobalConfig gc = new GlobalConfig();
    gc.setOutputDir(outputDir);
    gc.setSwagger2(true);
    gc.setAuthor("Leon");
    gc.setFileOverride(true);
    gc.setActiveRecord(false);
    // XML 二级缓存
    gc.setEnableCache(false);
    // XML ResultMap
    gc.setBaseResultMap(true);
    // XML columList
    gc.setBaseColumnList(true);

    mpg.setGlobalConfig(gc);

    // 数据源配置
    DataSourceConfig dsc = new DataSourceConfig();
    dsc.setDbType(DbType.MYSQL);
    dsc.setDriverName("com.mysql.jdbc.Driver");
    dsc.setUsername("root");
    dsc.setPassword("root");
    dsc.setUrl("jdbc:mysql://127.0.0.1:3306/rose?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false");

    mpg.setDataSource(dsc);

    // 策略配置
    StrategyConfig strategy = new StrategyConfig();
    strategy.setEntityLombokModel(true);
    strategy.setEntityBuilderModel(false);
    // 表名生成策略
    strategy.setNaming(NamingStrategy.underline_to_camel);
    mpg.setStrategy(strategy);

    // 包配置
    PackageConfig pc = new PackageConfig();
    pc.setParent("com.leon.rose.modules");
    pc.setModuleName("upms");
    pc.setController("controller");

    mpg.setPackageInfo(pc);

    mpg.execute();
  }

}